﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class DbHelper
    {
        public static string conString = "server=.;database=Net2;uid=SunBoy;pwd=010927";
        public static SqlDataReader DataReader(string cmdString)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            using (SqlCommand sqlCommand = new SqlCommand(cmdString, sqlConnection))
            {
                sqlConnection.Open();
                //返回查询之后的结果
                return sqlCommand.ExecuteReader();
            };
        }
        public static int Operation(string cmdString)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            using (SqlCommand sqlCommand = new SqlCommand(cmdString,sqlConnection))
            {
                sqlConnection.Open();
                //返回增删该改的结果
                return sqlCommand.ExecuteNonQuery();
            }
        }
    }
}
